package top.continew.admin.controller.pdnew;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.StrUtil;
import cn.shengchao.examstar.rpc.base.PageResult;
import cn.shengchao.examstar.rpc.base.TransResult;
import cn.shengchao.examstar.rpc.distribute.req.ThirdProductDistributeUserQueryPage;
import cn.shengchao.examstar.rpc.distribute.resp.ThirdProductDistributeForUserRespEntity;
import cn.shengchao.examstar.rpc.distribute.resp.ThirdProductDistributeProxyInfoRespEntity;
import cn.shengchao.examstar.rpc.orders.api.IOrderViewQueryRpc;
import cn.shengchao.examstar.rpc.orders.req.*;
import cn.shengchao.examstar.rpc.product.api.IContentProductTypeRpc;
import cn.shengchao.examstar.rpc.product.base.ContentProductType;
import cn.shengchao.examstar.rpc.product.base.ProductTypeTree;
import cn.shengchao.examstar.rpc.product.base.SimpleProduct;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.req.pdnew.ProductThirdDistributeProxySaveReq;
import top.continew.starter.web.model.R;

import java.util.List;

/**
 * @program: examstar-manger-api
 * @description: 订单查询
 * @author: Xiong weiqiang
 * @create: 2025-06-10 16:44
 */
@Tag(name = "订单查询")
@RestController
@RequiredArgsConstructor
@RequestMapping("/newOrderView")
public class OrderQueryController {
    @DubboReference
    private IOrderViewQueryRpc orderViewQueryRpc;

    @Operation(summary = "订单分页查询", description = "订单分页查询")
    @GetMapping("/pageQuery")
    PageResult<OrderWithSupplierView> pageQueryByUserId(OrderWithSupplierPageQuery pageQuery) {
        if (pageQuery==null){
            pageQuery=new OrderWithSupplierPageQuery();
            pageQuery.setPage(1);
            pageQuery.setSize(10);
        }
        if (StrUtil.isNotBlank(pageQuery.getOrderType())) {
            pageQuery.setProductTypes(pageQuery.getOrderType().equals(ContentProductType.COURSE.name())?List.of("COURSE"):List.of("PRODUCT_THIRD_CAP","PRODUCT_THIRD_YCBDC"));
        }
        return orderViewQueryRpc.pageList(pageQuery);
    }
    @Operation(summary = "订单子订单查询", description = "订单子订单查询")
    @GetMapping("/subOrder/{orderId}")
    R<List<SubOrderWithSupplierView>> subOrderListByOrderId(@PathVariable Long orderId) {
        return R.ok(orderViewQueryRpc.subOrderListForOrderId(orderId));
    }
    @Operation(summary = "订单子订单分页查询", description = "订单子订单查询")
    @GetMapping("/subOrder/pageFromMainOrder")
    R<List<SubOrderWithSupplierView>> subOrderPageFromMainOrder(SubOrderForMainPageQuery subOrderForMainPageQuery) {
        return R.ok(orderViewQueryRpc.subOrderPageFromMainOrder(subOrderForMainPageQuery));
    }

    @Operation(summary = "供应商子订单分页查询", description = "供应商子订单分页查询")
    @GetMapping("/subOrderPageQuery")
    PageResult<SubOrderWithSupplierView> subOrderPageQuery(SubOrderWithSupplierPageQuery pageQuery) {
        if (pageQuery==null){
            pageQuery=new SubOrderWithSupplierPageQuery();
            pageQuery.setPage(1);
            pageQuery.setSize(10);
        }
        Long userId= StpUtil.getLoginId(0L);
        pageQuery.setUserId(userId);
        if (StrUtil.isNotBlank(pageQuery.getOrderType())) {
            pageQuery.setProductTypes(pageQuery.getOrderType().equals(ContentProductType.COURSE.name())?List.of("COURSE"):List.of("PRODUCT_THIRD_CAP","PRODUCT_THIRD_YCBDC"));
        }
        return orderViewQueryRpc.subOrderPageList(pageQuery);
    }
}